package com.wchat.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

public class UserSettings {
	
	private static final String TAG = "user-setting";
	
	public static int getSettingInt(Context context, String settingName) {
		preparePreference(context);
		int value = preference.getInt(settingName, 0);
		Log.d(TAG, "get: key = " + settingName + ", value = " + value);
		return value;
	}
	
	public static long getSettingLong(Context context, String settingName) {
		preparePreference(context);
		long value = preference.getLong(settingName, 0);
		Log.d(TAG, "get: key = " + settingName + ", value = " + value);
		return value;
	}
	
	public static String getSettingString(Context context, String settingName) {
		preparePreference(context);
		String value = preference.getString(settingName, "");
		Log.d(TAG, "get: key = " + settingName + ", value = " + value);
		return value;
	}
	
	public static void putSettingInt(Context context, String settingName, int value) {
		preparePreference(context);
		editor.putInt(settingName, value);
		editor.commit();
		Log.d(TAG, "put: key = " + settingName + ", value = " + value);
	}
	
	public static void putSettingLong(Context context, String settingName, long value) {
		preparePreference(context);
		editor.putLong(settingName, value);
		editor.commit();
		Log.d(TAG, "put: key = " + settingName + ", value = " + value);
	}
	
	public static void putSettingString(Context context, String settingName, String value) {
		preparePreference(context);
		editor.putString(settingName, value);
		editor.commit();
		Log.d(TAG, "put: key = " + settingName + ", value = " + value);
	}

	private static void preparePreference(Context context) {
		if (preference == null || editor == null) {
			preference = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
			editor = preference.edit();
		}
	}
	
	public static interface Keys {
		
		public static final String ID = "ID";
		
		public static final String USER_NAME = "USER_NAME";
	
		public static final String SHARE_DIRECTORY = "SHARE_DIRECTORY";
		
	}
	
	public static interface Values {
	
	}
	
	private static final String PREFERENCE_NAME = "global_preference";
    
	private static SharedPreferences preference;
	
	private static Editor editor;

}
